# -*- coding: utf-8 -*-
import unittest
import os.path

from model.gamestate import *
from cur_result import CurResults
from presenter_mock import PresenterMock


def create_round(p1, p2, cnt):
    game_round = GameRound(0, [], None, (p1, p2))
    for i in range(cnt):
        word_guess_result = WordGuessResult(Word(p1, u"W"),
                                            WordGuessResult.GUESS, 5)
        game_round.words.append(word_guess_result)
    return game_round


class GuessWordTest(unittest.TestCase):
    def setUp(self):
        players = Players([Player(u'Андрей', []), Player(u'Петр', []),
                           Player(u'Иван', []), Player(u'Ольга', []),
                           Player(u'Миша', []), Player(u'Петя', [])])
        players.set_next_pair_strategy(OddStrategy(players.players))
        hat = Hat([u'стул', u'шапка', u'кастрюлька'])
        rounds = [
            create_round(players.players[0], players.players[1], 10),
            create_round(players.players[2], players.players[3], 15),
            create_round(players.players[1], players.players[0], 15),
            create_round(players.players[3], players.players[2], 5),
            create_round(players.players[4], players.players[5], 5),
        ]

        self.gamestate = GameState(players, hat, None, 0,
                                   rounds, None, Settings(20, 30))

    def test_go_back(self):
        self.presenter = PresenterMock(Phase.FROM_TO)
        widget = CurResults(self.gamestate, self.presenter)
        self.assertEquals(self.presenter.is_phase_changed, False)
        widget.go_back()
        self.assertEquals(self.presenter.is_phase_changed, True)

    def test_end_game(self):
        self.presenter = PresenterMock(Phase.WELCOME)
        widget = CurResults(self.gamestate, self.presenter)
        self.assertEquals(self.presenter.is_phase_changed, False)
        widget.end_game()
        self.assertEquals(self.presenter.is_phase_changed, True)


if __name__ == '__main__':
    unittest.main()
